﻿using System.Text.RegularExpressions;
using System.Globalization;
using System.Windows.Controls;

namespace WpfTwitterClient.Modules.Authorization
{
    public class TwitterPinValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            string pin = value.ToString();
            if (string.IsNullOrEmpty(pin))
                return new ValidationResult(false, "Pin number cannot be blank");

            Regex re = new Regex("^[0-9]{7,7}$");
            
            if (!re.IsMatch(pin))
                return new ValidationResult(false, "Pin number must be 7 digits long");

            return ValidationResult.ValidResult;
        }
    }
}
